// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import GameEvent from "../../Commons/GameEvent";
import { getZeroTime } from "../../GlobalFunction";
import SaveManager from "../../Managers/SaveManager";
import UIManager from "../../Managers/UIManager";
import CharacterTemplate from "../Characters/CharacterTemplate";

const { ccclass, property } = cc._decorator;

@ccclass
export default class FuBenManager implements IModelManager {

    private static _single: FuBenManager = null;
    private _challengeTime: number = 0;
    public get challengeTime(): number {
        return this._challengeTime;
    }
    public set challengeTime(value: number) {
        this._challengeTime = value;
    }

    public static get single(): FuBenManager {

        if (FuBenManager._single == null) {
            FuBenManager._single = new FuBenManager();
        }
        return FuBenManager._single;
    }

    initConfig(): void {

    }

    getFuBenCount(): number {
        return SaveManager.single.userdata.fubenCount;
    }

    requestChallenge(tp: CharacterTemplate) {
        var userdata = SaveManager.single.userdata;

        userdata.fubenCount--;
        SaveManager.single.saveData();
        GameEvent.eventNode.emit(GameEvent.STARTFUBEN_EVENT, tp);
    }

    requestResetFuBenCount() {
        var userdata = SaveManager.single.userdata;
        let leftTime = cc.sys.now() - userdata.fubenCountTime;
        if (leftTime >= 24 * 60 * 60 * 1000) {//
            userdata.fubenCountTime = getZeroTime();
            userdata.fubenCount = 5;
            SaveManager.single.saveData();
        }
    }

}
